package com.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.entity.Dep;
import com.service.DepServiceImpl;
import com.vo.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin("*")
@RequestMapping("/api")
public class DepController {

    @Autowired
    private DepServiceImpl depService;


    @RequestMapping("/searchDep")
    public ResponseBean searchDep(@RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10")int limit,Integer depId,String depName){

        IPage pageSearch=depService.pearchDep(page,limit,depId,depName);
        return new ResponseBean(0,pageSearch.getTotal(),pageSearch.getRecords());
    }

    /**
     * 查询  参数放 地址栏  查询 请求一般是 Get
     * 增删改都 放 请求体   删除是 Delete     增是 post   改是 put     但也可以 都用post
     * @param dep
     * @return
     */
    @RequestMapping(value = "/addDep",method = RequestMethod.POST)
    public ResponseBean addDep(@RequestBody Dep dep){
        int n=depService.addDep(dep);
        if(n>0){
            return new ResponseBean(200,0,"新增成功");
        }else {
            return new ResponseBean(500,0,"新增失败");

        }
    }


}
